#ifndef __CONTROL_H__

#define __CONTROL_H__

typedef int CONTROL_ERR;
#define CONTROL_OK                  0x00
#define CONTROL_NOT_ALLOWED         0x01
#define CONTROL_UNKNOWN_ERROR       0x02
#define CONTROL_HEXAGON_NOT_REACHED 0x03
#define CONTROL_NOT_A_TERRITORY     0x04

typedef char bool;
#define TRUE  't'
#define FALSE 'f'

typedef char color;
#define LIGHTGREEN 'g'
#define DARKGREEN  'G'
#define YELLOW     'y'
#define BROWN      'b'
#define BLUE       'B'
#define RED        'r'
#define PINK       'p'
#define BLACK      'k'

typedef char searchState;
#define WHITE  'w'
#define GRAY   'g'
#define BLACK  'k'
#define RED    'r'
#define ORANGE 'o'

typedef char level;
#define UNPROTECTED 0x0
#define MILITIA     0x1
#define CAPITAL     0x1
#define SOLDIER     0x2
#define FORT        0x2
#define WARRIOR     0x3
#define CHAMPION    0x4

struct hexagon;

typedef struct Human{

  color clr;
  level lvl;
  bool canMove;

  struct hexagon * territoryCapital;
  struct hexagon * myPlace;

} human;

typedef struct hexagon{

  color clr;
  bool drawn;

  struct hexagon * mapNeighs[6];

  struct hexagon * territoryNeighs[6];
  struct hexagon * territoryCapital;

  bool isCapital;
  int funds;
  int numberHumans;
  human **Humans;

  bool isTree;

  bool isFort;

  human * whoHere;

  searchState ss;
  struct hexagon * bSearch;

} field;

field **lightGreenTerritories;
field **darkGreenTerritories;
field **yellowTerritories;
field **brownTerritories;
field **blueTerritories;
field **redTerritories;
field **pinkTerritories;
field **blackTerritories;

int lightGreenTerritoriesNumber;
int darkGreenTerritoriesNumber;
int yellowTerritoriesNumber;
int brownTerritoriesNumber;
int blueTerritoriesNumber;
int redTerritoriesNumber;
int pinkTerritoriesNumber;
int blackTerritoriesNumber;

CONTROL_ERR placeHuman(human *hmn, field *fld);
CONTROL_ERR placeFort(field *capital, field *fld);
level analyzeProtection(field *fld);
level returnProtector(field *fld);
CONTROL_ERR placeHumanInFriendlyField(human *hmn, field *fld);
bool sameTerritoryOrBorder(field *capital, field *fld);
void conquestHexagon(human *hmn, field *fld);
void executeMarking(field *root);
CONTROL_ERR buildTerritory(field *capital);
void addTerritory(field *capital, color clr);
CONTROL_ERR checkAllHexagonsInTerritory(field *capital, field *fld, field **notReached);
void adjustTerritories(color clr);
void clearSearchState(field *fld);
void freeHumans(field *capital);
void killHuman(human *hmn);
human* hireHuman(field *capital, level lvl, field *fld);
void collectHumans(field *capital, field *root);
void addHuman(field *capital, human *hmn);

#endif
